home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac 1993 September / clonecd / September 93.img / Archives / Utilities / Quicktime / SLINK's VCR QuickTime / MP Source / Dlog.c < prev    next >
Text File  |  1992-06-15  |  5KB  |  228 lines

  1. /*---------------------------------------------------------------------
  2.     Program: Dlog.c
  3.     By: Geoffrey Slinker
  4.     Date: 11:59:55 AM  5/2/92
  5.     Purpose: Contains methods for Dlog class, see Dlog.h
  6. ---------------------------------------------------------------------*/
  7. #include <stdio.h>
  8. #include <string.h>
  9.  
  10. #include "Dlog.h"
  11. #include "Alert_Class.h"
  12.  
  13. extern Alert_Class *myAlert;
  14. /**********************************************************************/
  15. Dlog::Dlog(void)    // constructor code
  16. {    
  17.     myDlog = NULL;
  18.     rsrcNumber = 0;
  19.     itemHit = 0;
  20.     itemType = 0;
  21.     dialogDone = 0;
  22. }
  23. /*....................................................................*/
  24. Dlog::~Dlog(void)    // destructor code
  25. {    
  26.     DialogPtr myDlog;
  27.     int rnum;
  28.     
  29.     /*-------------------------
  30.     Shadow for purging problems
  31.     -------------------------*/
  32.     myDlog = this->myDlog;
  33.     rnum = this->rsrcNumber;
  34.     if ( myDlog != NULL  ) {
  35.         FreeDialog(rsrcNumber);
  36.         DisposDialog(myDlog);
  37.     } /* end if */
  38.     this->myDlog = NULL;
  39. }
  40. /*....................................................................*/
  41. void Dlog::loadResource( int number)    // load resource from resource file
  42. {
  43.     DialogPtr myDlog;
  44.     
  45.     /*-------------------------
  46.     Shadow for purging problems
  47.     -------------------------*/
  48.     myDlog = this->myDlog;
  49.     rsrcNumber = number;
  50.     myDlog = GetNewDialog(number,0L,(WindowPtr)-1L);
  51.     
  52.     if ( myDlog == 0L  ) {
  53.         SysBeep(7);
  54.         (*myAlert).AlertStop("\pFatal Error",
  55.                             "\pUnable to allocate new dialog",
  56.                             "\pDlog::loadResource",NULL);
  57.     } /* end if */
  58.     
  59.     CouldDialog(rsrcNumber);    // could be purged so lock it down
  60.     
  61.     /*-------------------------
  62.     Copy back from shadow
  63.     -------------------------*/
  64.     this->myDlog = myDlog;
  65.  
  66. }
  67. /*....................................................................*/
  68. /* This routine simply shows the dialog box and when you click in it
  69.     it close, used mostly for testing position and look, not used
  70.     in the final application code
  71. */
  72. void Dlog::showDialog()
  73. {
  74.     EventRecord smallEvent;
  75.     WindowPtr whichWindow;
  76.     GrafPtr oldPort;
  77.     int done = 0;
  78.     DialogPtr myDlog;
  79.     
  80.     /*-------------------------
  81.     Shadow for purging problems
  82.     -------------------------*/
  83.     myDlog = this->myDlog;
  84.     
  85.     SetItemValues();
  86.  
  87.     GetPort(&oldPort);
  88.     SetPort(myDlog);
  89.     SelectWindow(myDlog);
  90.     DrawDialog(myDlog);
  91.     
  92.  
  93.     while ( !done  ) {
  94.         SystemTask();
  95.         
  96.         GetNextEvent((mDownMask + mUpMask),&smallEvent);
  97.         
  98.         switch ( smallEvent.what  ) {
  99.             case mouseDown:
  100.                 FindWindow(smallEvent.where,&whichWindow);
  101.                 if ( whichWindow == myDlog  ) {
  102.                     done = 1;
  103.                 }
  104.                 else {
  105.                     SysBeep(7);
  106.                 } /* end if then else */
  107.                 break;
  108.             
  109.             default: break;
  110.         } /* end switch */
  111.     } /* end while */
  112.     
  113.     HideWindow(myDlog);
  114.     
  115.     SetPort(oldPort);
  116. }
  117. /*....................................................................*/
  118. void Dlog::HandleDialog(EventRecord *aEvent)
  119. {
  120.     DialogPtr myDlog;
  121.     int itemHit;
  122.     int dialogDone;
  123.     GrafPtr aPort;
  124.     Point thePoint;
  125.     int thePart;
  126.  
  127.     
  128.     /*-------------------------
  129.     Shadow for handle protection
  130.     -------------------------*/
  131.     myDlog = this->myDlog;
  132.     itemHit = this->itemHit;
  133.     //dialogDone = this->dialogDone;
  134.     
  135.     
  136.     // this was an experiment in handling dialog events in their
  137.     // class instead of the main event loop.
  138.     switch ( (*aEvent).what  ) {
  139.         
  140.         case updateEvt:
  141.             GetPort(&aPort);
  142.             SetPort((WindowPtr)(*aEvent).message);
  143.  
  144.             BeginUpdate((WindowPtr)(*aEvent).message);
  145.                 RedrawDialog();
  146.             EndUpdate((WindowPtr)(*aEvent).message);
  147.             SetPort(aPort);
  148.             break;
  149.             
  150.         case nullEvent:
  151.             SystemTask();
  152.             break;
  153.                 
  154.         default: break;
  155.     } /* end switch */
  156.     
  157.     thePoint = (*aEvent).where;
  158.     GlobalToLocal(&thePoint);
  159.  
  160.     thePart = FindControl(thePoint,myDlog,&itemHandle);            
  161.     if (DialogSelect(aEvent,&myDlog,&itemHit) ) {
  162.         HandleDialogItem(itemHit,thePoint,thePart);
  163.     }
  164. }
  165. /*....................................................................*/
  166. /* Should be overloaded or something! */
  167. int Dlog::HandleDialogItem(int itemHit, Point thePoint, int thePart)
  168. {
  169.     DialogPtr myDlog;
  170.     Handle itemHandle;
  171.     Rect itemRect;
  172.     int itemType;
  173.     
  174.     myDlog = this->myDlog;
  175.     itemHandle = this->itemHandle;
  176.     itemRect = this->itemRect;
  177.     
  178.     switch ( itemHit  ) {
  179.         
  180.         default: break;
  181.     } /* end switch */
  182. }
  183. /*....................................................................*/
  184. void Dlog::SetItemValues()
  185. {
  186.     /*-------------------------
  187.     Sets item values.    
  188.     -------------------------*/
  189. }
  190. /*....................................................................*/
  191. void Dlog::PutUpDialog()
  192. {
  193.     DialogPtr myDlog;
  194.     
  195.     myDlog = (*this).myDlog;
  196.     
  197.     ShowWindow(myDlog);    
  198.     SetPort(myDlog);
  199.     SelectWindow(myDlog);
  200.     DamageDialog();
  201. }
  202. /*....................................................................*/
  203. void Dlog::RedrawDialog()
  204. {
  205.     DialogPtr myDlog;
  206.     GrafPtr oldPort;
  207.     
  208.     GetPort(&oldPort);
  209.     
  210.     myDlog = (*this).myDlog;
  211.     
  212.     SetPort(myDlog);
  213.     DrawDialog(myDlog);
  214.     SetPort(oldPort);
  215. }
  216. /*....................................................................*/
  217. void Dlog::DamageDialog()
  218. {
  219.     Rect theRect;
  220.     DialogPtr myDlog;
  221.     
  222.     myDlog = (*this).myDlog;
  223.     
  224.     theRect = (*myDlog).portRect;
  225.     InvalRect(&theRect);
  226. }
  227. /**********************************************************************/
  228.